import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class PlayerView {
	private Player player;
	private SOCApplet applet;
	private int xCoord;
	private int yCoord;
	private BufferedImage playerPanel;
	private int size;
	
	public PlayerView(Player p, SOCApplet applet){
		player = p;
		this.applet = applet;
		size = 50;
		try {
			playerPanel = ImageIO.read(new File("player_panel.jpg"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void drawSelf(Graphics g){
		g.setFont(new Font("Helvetica", Font.PLAIN, 14));
		int turnNo = applet.getPlayers().lastIndexOf(applet.getTurn().getPlayer());
		int location = (applet.getPlayers().indexOf(this.player) - turnNo + 4) % 4;
		if (location == 1){
			xCoord = 0;
			yCoord = 0;
		} else if (location == 2){
			xCoord = 550;
			yCoord = 0;
		} else if (location == 3){
			xCoord = 550;
			yCoord = 500;
		}
		g.drawImage(playerPanel, xCoord, yCoord, null);
		int vPts = player.getvPts();
		int roadNum = player.roadNum;
		int armyNum = player.getArmyNum();
		int specialCards = player.getHand().getCards().size();
		int specialVPts = player.getSpecialVPts();
		int rCardsNum = player.getBrick() + player.getGrain() + player.getLumber() + player.getOre() + player.getWool();
		g.setColor(Color.BLACK);
		g.drawString(vPts + "", xCoord + 10, yCoord + 75);
		if (player.hasLargeArmy()){
			g.setColor(Color.RED);
		}
		g.drawString(armyNum + "", xCoord + 80, yCoord + 75);
		g.setColor(Color.BLACK);
		if (player.isHasLongRoad())
			g.setColor(Color.RED);
		g.drawString(roadNum + "", xCoord + 45, yCoord + 75);
		g.setColor(Color.BLACK);
		g.drawString(specialCards + "", xCoord + 115, yCoord + 75);
		g.drawString(specialVPts + "", xCoord + 150, yCoord + 75);
		g.drawString(rCardsNum + "", xCoord + 185, yCoord + 75);
		g.setFont(new Font("Helvetica", Font.BOLD, 22));
		
		g.drawString(player.orderNum + " ", xCoord + 20, yCoord + 20);
		g.setFont(new Font("Helvetica", Font.PLAIN, 14));
	}
}
